package com.example.goodsprovider.controller;

import com.example.goodscommons.pojo.Book;
import com.example.goodsprovider.service.GoodsProviderService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/provider")
public class GoodsProviderController {

    @Resource
    private GoodsProviderService goodsProviderService;


    @RequestMapping("/test")
    @ResponseBody
    public String testGoodsUi() {
        System.out.println("进入了goods-provider~~~~");
        return "success";
    }


    @RequestMapping("/list")
    public List<Book> bookList(){
        List<Book> bookList=goodsProviderService.getBookList();
        return bookList;
    }

    @RequestMapping("/detail/{id}")
    public Book detail(@PathVariable("id")Integer id){

        Book book=goodsProviderService.getBookDetail(id);
        return book;

    }

//    @RequestMapping("/detail/{id}")
//    public Book getBookById(@PathVariable("id")Integer id){
//        Book book = goodsProviderService.getBookById(id);
//        return book;
//    }


    @PostMapping("/add")
    public String add(@RequestBody Book book){
        goodsProviderService.addBook(book);
        return "success";
    }
}